/**
 * Created by Baggio on 2017/3/2.
 */
$(function () {

    $("#modifyUserSubmit").click(function () {
        if ($("#userName").val() == '') {
            alert("请输入账号！");
            return;
        }

        $("#adminUserForm").ajaxSubmit({
            type: "POST",
            url: '/user/modifyUser.html',
            data: $('#adminUserForm').serialize(),// 你的formid
            error: function (request) {
                $("#loading").hide();
                alert("Connection error");
            },
            beforeSend: function () {
                console.log("begin...............");
                $(".loading").show();

            },
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    alert(data.msg);
                    return;
                }

                alert(data.msg);
            },
            complete: function (XMLHttpRequest, textStatus) {
                // alert('远程调用成功，状态文本值：'+textStatus);
                console.log("end...............");
                $(".loading").hide();
            },
        });

    })

});

$(function () {
    $("#userName").blur(function () {
        $.ajax({
            type: "POST",
            url: "/user/selectUserName.html",
            data: {"userName": $("#userName").val()},
            dataType: "json",
            success: function (data) {
                if (data.data == null) {
                    $("#isUserNameOk").html("用户名可以使用！");
                } else {
                    $("#isUserNameOk").html("用户名重复，请更换用户名！")
                }
            }
        })
    })
})

$(function () {
    $("#userAddOk").click(function () {
        $("#userAddForm").ajaxSubmit({
            type: "POST",
            url: '/user/addUser.html',
            data: $('#userAddForm').serialize(),
            dataType: "json",
            error: function (jqXHR, textStatus, errorThrown) {
                alert("Connection error");
            },
            success: function (data) {
                layer.msg('操作成功!', {icon: 6, time: 1000}, function () {
                    console.log(data);
                    window.parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                })
            }
        });
    })
})

function stopAdminUser(tid) {
    $.ajax({
        type: "POST",
        url: '/user/stopAdminUser.html',
        data: {"tid": tid},// 你的formid
        dataType: "json",
        success: function (data) {
            console.log(data);
            if (data.code != 0) {
                layer.msg('停用成功!', {icon: 6, time: 1000}, function () {
                    console.log(data);
                    window.location.reload();
                })
            }
        },
    });
}

function operateAdminUser(tid, aaa) {
    $.ajax({
        type: "POST",
        url: '/user/addUser.html',
        data: {"tid": tid, "status": aaa},// 你的formid
        dataType: "json",
        success: function (data) {
            console.log(data);
            if (data.code != 0) {
                layer.msg('操作成功!', {icon: 6, time: 1000}, function () {
                    console.log(data);
                    window.location.reload();
                })
            }
        },
    });
}

function resetPassword(tid) {
    $.ajax({
        type: "POST",
        url: '/user/resetPassword.html',
        data: {"tid": tid},// 你的formid
        dataType: "json",

        success: function (data) {
            console.log(data);
            if (data.code != 0) {
                layer.msg('重置成功!', {icon: 6, time: 1000}, function () {
                    console.log(data);
                    window.location.reload();
                })
            }
        },
    });
}


